#!/bin/sh /etc/rc.common
START=15

NAME="cpufreq"

config_get_cpufreq()
{
	config_get "$NAME" "$1"
}

start()
{
	config_load "$NAME"

	for i in $(find /sys/devices/system/cpu/cpufreq/policy* -maxdepth 0 | grep -Eo '[0-9]+')
	do
		[ -z "$(config_get_cpufreq "governor$i")" ] && return

		config_get_cpufreq "governor$i" > "/sys/devices/system/cpu/cpufreq/policy$i/scaling_governor"
		config_get_cpufreq "minfreq$i" > "/sys/devices/system/cpu/cpufreq/policy$i/scaling_min_freq"
		config_get_cpufreq "maxfreq$i" > "/sys/devices/system/cpu/cpufreq/policy$i/scaling_max_freq"
		if [ "$(config_get_cpufreq "governor$i")" = "ondemand" ]; then
			config_get_cpufreq "sdfactor$i" > "/sys/devices/system/cpu/cpufreq/ondemand/sampling_down_factor"
			config_get_cpufreq "upthreshold$i" > "/sys/devices/system/cpu/cpufreq/ondemand/up_threshold"
		fi
	done
}
